package com.ruoyi.supermarket.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.supermarket.domain.Vo.TempCxCcVO;
import com.ruoyi.supermarket.domain.Vo.TempCxDdVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.supermarket.domain.TempCx;
import com.ruoyi.supermarket.service.ITempCxService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采销Controller
 * 
 * @author ruoyi
 * @date 2024-05-19
 */
@RestController
@RequestMapping("/supermarket/cx")
public class TempCxController extends BaseController
{
    @Autowired
    private ITempCxService tempCxService;

    /**
     * 查询采销列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:cx:list')")
    @GetMapping("/list")
    public AjaxResult list(TempCx tempCx)
    {
        List<TempCx> list = tempCxService.selectTempCxList(tempCx);
        return AjaxResult.success(list);
    }
    /**
     * 查询采销列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:cx:list')")
    @GetMapping("/listXs")
    public AjaxResult listXs(TempCx tempCx)
    {
        List<TempCx> list = tempCxService.selectTempCxXsList(tempCx);
        return AjaxResult.success(list);
    }

    /**
     * 获取采销详细信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:cx:query')")
    @GetMapping(value = "/{tId}")
    public AjaxResult getInfo(@PathVariable("tId") Long tId)
    {
        return success(tempCxService.selectTempCxByTId(tId));
    }

    /**
     * 新增采销
     */
    @PreAuthorize("@ss.hasPermi('supermarket:cx:add')")
    @Log(title = "采销", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TempCx tempCx)
    {
        return toAjax(tempCxService.insertTempCx(tempCx));
    }


    /**
     * 修改采销
     */
    @PreAuthorize("@ss.hasPermi('supermarket:cx:edit')")
    @Log(title = "采销", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TempCx tempCx)
    {
        return toAjax(tempCxService.updateTempCx(tempCx));
    }

    /**
     * 删除采销
     */
    @PreAuthorize("@ss.hasPermi('supermarket:cx:remove')")
    @Log(title = "采销", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tId}")
    public AjaxResult remove(@PathVariable Long tId)
    {
        return toAjax(tempCxService.deleteTempCxByTId(tId));
    }


    @DeleteMapping
    public AjaxResult delAll (){
        return tempCxService.deleteAll();
    }


    /**
     * 保存临时订单
     */
    @PreAuthorize("@ss.hasPermi('supermarket:cx:Dd')")
    @Log(title = "临时订单", businessType = BusinessType.INSERT)
    @PostMapping("/Dd")
    public AjaxResult Dd(@RequestBody TempCxDdVO tempCxDdVO)
    {
        return tempCxService.insertDd(tempCxDdVO);
    }

    /**
     * 差停用
     */
    @Log(title = "临时订单", businessType = BusinessType.INSERT)
    @PostMapping("/tempDdCc")
    public AjaxResult tempDdCc(@RequestBody TempCxCcVO tempCxCcVO )
    {
        return tempCxService.selectTempDdCc(tempCxCcVO);
    }
}
